//
//  LLStatusTooBarView.swift
//  xinlangweibo
//
//  Created by 任玉林 on 16/6/29.
//  Copyright © 2016年 任玉林. All rights reserved.
//

import UIKit

class LLStatusTooBarView: UIView {
    var retweetButton: UIButton?
    var commentButton: UIButton?
    var unlikeButton: UIButton?
    
    var status:LLStatusesModel?{
        
        didSet{
            
            retweetButton?.setTitle(status?.repostsStr, forState: UIControlState.Normal)
            
            commentButton?.setTitle(status?.commentsStr, forState: UIControlState.Normal)
            
            unlikeButton?.setTitle(status?.attitudesStr, forState: UIControlState.Normal)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
 

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        
//        backgroundColor = randomColor()
        
        retweetButton = addChildButton("timeline_icon_retweet", title: "转发")
        
        commentButton = addChildButton("timeline_icon_comment", title: "评论")
        
        unlikeButton = addChildButton("timeline_icon_unlike", title: "赞")
        
       let line1 =  addChildLine()
        
       let line2 = addChildLine()
        
        //设置约束
        retweetButton?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.top.leading.bottom.equalTo(self)
            
            make.width.equalTo(commentButton!)
            
        })
        
        
        commentButton?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetButton!.snp_trailing)
            make.width.equalTo(unlikeButton!)
        })
        
        unlikeButton?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.top.bottom.trailing.equalTo(self)
            make.leading.equalTo(commentButton!.snp_trailing)
        })
        
        line1.snp_makeConstraints { (make) -> Void in
            
            make.centerY.equalTo(self)
            make.centerX.equalTo(retweetButton!.snp_trailing)
        }
        
        line2.snp_makeConstraints { (make) -> Void in
            
            make.centerY.equalTo(self)
            make.centerX.equalTo(commentButton!.snp_trailing)
        }
    }


    //创建button
    private func addChildButton(imageName:String,title:String)->UIButton{
        
        let button = UIButton()
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        
        button.setTitle(title, forState: UIControlState.Normal)
        
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        
        addSubview(button)
        
        return button
    }
    
    private func addChildLine()->UIImageView{
        
        let img = UIImageView(imageName: "timeline_card_bottom_line")
        
        addSubview(img)
        
        return img
        
            }
}
